//
//  YCClassStyleDescViewController.m
//  YCSchool
//
//  Created by yanglinxia on 16/4/29.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  班型说明

#import "YCClassStyleDescViewController.h"
#import "YCClassStyleCell.h"
#import "YCClassStyleModel.h"

@interface YCClassStyleDescViewController ()<UITableViewDelegate,UITableViewDataSource>

/** tableView */
@property (nonatomic, strong) UITableView *tableView;
/** 数据  */
@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation YCClassStyleDescViewController

- (NSArray *)dataArray
{
    if (!_dataArray) {
        YCClassStyleModel *model = [[YCClassStyleModel alloc] init];
        model.img = @"特惠班";
        model.title = @"特惠班";
        model.des = @"集中式教学培训";
        model.selected = NO;
        model.desc = YES;
        
        YCClassStyleModel *model1 = [[YCClassStyleModel alloc] init];
        model1.img = @"周末班";
        model1.title = @"周末班";
        model1.des = @"集中式教学培训";
        model1.selected = NO;
        model1.desc = YES;
        
        YCClassStyleModel *model2 = [[YCClassStyleModel alloc] init];
        model2.img = @"VIP班";
        model2.title = @"VIP班";
        model2.des = @"一对一高质量教学";
        model2.selected = NO;
        model2.desc = YES;
        
        _dataArray = @[model,model1,model2];
    }
    return _dataArray;
}

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.yc_width, self.view.yc_height-64) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.backgroundColor = [UIColor yc_colorWithUInt:0xf7f7f7];
    }
    return _tableView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"班型介绍";
    
    [self yc_addBackBarButtonItem];
    [self.view addSubview:self.tableView];
    self.tableView.contentInset = UIEdgeInsetsMake(12, 0, 0, 0);//18 = 12 + 6
    self.tableView.rowHeight = 135;// 123+间距12(上下各6)
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    UINavigationBar *bar = self.navigationController.navigationBar;
    [bar setShadowImage:[UIImage yc_imageWithColor:[UIColor clearColor] size:CGSizeMake(kScreenWidth, 1)]];
    [bar setBackgroundImage:[UIImage yc_imageWithColor:[UIColor yc_colorWithUInt:0xf7f7f7] size:CGSizeMake(kScreenWidth, 64)] forBarMetrics:UIBarMetricsDefault];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    // 还原导航条背景
    UINavigationBar *bar = self.navigationController.navigationBar;
    [bar setShadowImage:[UIImage yc_imageWithColor:[UIColor clearColor] size:CGSizeMake(kScreenWidth, 1)]];
    [bar setBackgroundImage:[UIImage yc_imageWithColor:[UIColor whiteColor] size:CGSizeMake(kScreenWidth, 64)] forBarMetrics:UIBarMetricsDefault];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YCWeakSelf
    YCClassStyleCell *cell = [YCClassStyleCell tableViewCellWithTableView:tableView withIndexPath:indexPath detailButtonActionBlock:^{
        // 点击详情介绍按钮处理处
        YCClassStyleModel *mode = weakSelf.dataArray[indexPath.row];
        YCLog(@"是否选中:%@",mode.title);
    }];
    cell.contentView.backgroundColor = [UIColor yc_colorWithUInt:0xf7f7f7];
        cell.itemModel = self.dataArray[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    YCClassStyleModel *model = self.dataArray[indexPath.row];
    for (YCClassStyleModel *otherModel in self.dataArray) {
        if (otherModel != model) {
            otherModel.selected = NO;
        }
    }
    model.selected = !model.isSelected;
    [tableView reloadData];
}


#pragma mark - 点击事件




@end
